#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

char* addBinary(char* a, char* b);

int main()
{
	return 0;
}

char* addBinary(char* a, char* b)
{
	int lenA = strlen(a),
		lenB = strlen(b);

	int lo = 0, hi = lenA - 1;
	while (lo < hi) {
		char temp = a[lo];
		a[lo++] = a[hi];
		a[hi--] = temp;
	}
	lo = 0, hi = lenB - 1;
	while (lo < hi) {
		char temp = b[lo];
		b[lo++] = b[hi];
		b[hi--] = temp;
	}

	char* res = calloc(fmax(lenA, lenB) + 2, sizeof(char));
	char chA, chB, carry = 0;
	int idx = 0;
	for (; (chA = a[idx]) && (chB = b[idx]); idx++) {
		printf("%c, %c\n", chA, chB);
		char cur = chA + chB - '0' + carry;
		if (cur == '3') {
			res[idx] = '1';
		} else if (cur == '2') {
			res[idx] = '0';
			carry = 1;
		} else if (cur == '1') {
			res[idx] = '1';
			carry = 0;
		} else {
			res[idx] = '0';
		}
	}

	if ((chB = b[idx])) a = b;
	while ((chA = a[idx])){
		char cur = chA + carry;
		if (cur == '2')
			res[idx] = '0';
		else if (cur == '1') {
			res[idx] = '1';
			carry = 0;
		} else
			res[idx] = '0';
		idx++;
	}

	if (carry) res[idx++] = '1';

	lo = 0, hi = idx - 1;
	while (lo < hi) {
		char temp = res[lo];
		res[lo++] = res[hi];
		res[hi--] = temp;
	}
	return res;
}